package com.erp.erp_servers.bill_exchange.Imp;

import com.erp.erp_dao.BillExchangeInfo.IBillExchangeProductInfoDao;
import com.erp.erp_entitys.BillExchangeInfo.BillExchangeProductInfo;
import com.erp.erp_servers.bill_exchange.BillExchangeProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 结汇产品明细表(BillExchangeProductInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-01-15 21:13:36
 */
@Service("billExchangeProductInfoService")
public class BillExchangeProductInfoServiceImpl implements BillExchangeProductInfoService {

    private final IBillExchangeProductInfoDao billExchangeProductInfoDao;

    @Autowired
    public BillExchangeProductInfoServiceImpl(IBillExchangeProductInfoDao billExchangeProductInfoDao) {
        this.billExchangeProductInfoDao = billExchangeProductInfoDao;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param billProductId 主键
     * @return 实例对象
     */
    @Override
    public BillExchangeProductInfo queryById(Integer billProductId) {
        return this.billExchangeProductInfoDao.queryById(billProductId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BillExchangeProductInfo> queryAllByLimit(int offset, int limit) {
        return this.billExchangeProductInfoDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<BillExchangeProductInfo> queryAll(BillExchangeProductInfo productInfo) {
        return  this.billExchangeProductInfoDao.queryAll(productInfo);
    }

    /**
     * 新增数据
     *
     * @param billExchangeProductInfo 实例对象
     * @return 实例对象
     */
    @Override
    public BillExchangeProductInfo insert(BillExchangeProductInfo billExchangeProductInfo) {
        this.billExchangeProductInfoDao.insert(billExchangeProductInfo);
        return billExchangeProductInfo;
    }

    /**
     * 修改数据
     *
     * @param billExchangeProductInfo 实例对象
     * @return 实例对象
     */
    @Override
    public BillExchangeProductInfo update(BillExchangeProductInfo billExchangeProductInfo) {
        this.billExchangeProductInfoDao.update(billExchangeProductInfo);
        return this.queryById(billExchangeProductInfo.getBillProductId());
    }

    /**
     * 通过主键删除数据
     *
     * @param billProductId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer billProductId) {
        return this.billExchangeProductInfoDao.deleteById(billProductId) > 0;
    }

    @Override
    public BigDecimal selectLastAmount(BillExchangeProductInfo info) {
        return billExchangeProductInfoDao.selectLastAmount(info);
    }


}